/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package javaapplication6.UI;

import javaapplication6.DomainLayer.Worker;

/**
 *
 * @author meydlo
 */
public class MainUI {

    private Listener listener;
    private LoginUI getLogin;
    private boolean exit;
    private int type;
    private Worker worker;
    private long idOfWorker;

    public MainUI(){
        listener=new Listener();
        getLogin=new LoginUI();
        exit=false;
        worker=getLogin.logIn();
        type=worker.getType();
        idOfWorker=worker.getId();
        
    }


    public void printChoices()
    {
        System.out.println(
                "\n (1) customer manager"+
                "\n (2) workers manager"+
                "\n (3) ordering manager"+
                "\n (4) product manager"+
                "\n (5) statistics manager"+
                "\n (6) switch user"+
                "\n (7) exit"
                );
    }
    public void mainManager()
    {
        printWelcome();
         do{
            printChoices();
            int number=listener.getLineInt();

            switch(number){
                case 1:{
                    CustomerUI customerUI=new CustomerUI();
                    customerUI.CustomerManager();
                    break;
                }
                // only manager have access to this part
                //
                case 2:{
                    WorkerUI workerUI=new WorkerUI();
                    if(type==3){
                    workerUI.WorkerManager();
                    }
                    else{
                        System.out.println("\nyou are not permited!");
                        System.out.println("changes limited by your account");

                        //long workerId=login.logIn().getId();
                        workerUI.updateWorkerNoChoosed(idOfWorker);
                    }
                    break;
                }
                case 3:{
                    SellRentOrder();
                    break;
                }
                case 4:{
                    
                    if(type==3){
                    productManagingUI();
                    }
                    else{
                        System.out.println("\nyou are not permited");
                    }
                    break;
                }
                case 5:{
                    if(type==3){
                        StatisticsUI statisticsUI=new StatisticsUI();
                        statisticsUI.statisticsManager();
                    }
                    else{
                        System.err.println("you are not permited");
                    }
                    break;
                }
                case 6:{
                    try{
                        worker=getLogin.logIn();
                        type=worker.getType();
                         printWelcome();
                    }
                    catch(Exception e){
                    }
                    break;
                }
                case 7:{
                    System.out.println("bye");
                    exit=true;
                    break;
                }
                default:{
                    System.out.println("Valid rank is: 1-7");
                }
            }
        }while(exit==false);
    }

    public void setWorkerId()
    {
        try{
            idOfWorker=worker.getId();
        }
        catch(Exception e){

        }
    }

    //writethat
    public void setWorkerType()
    {
        try{
            type= worker.getType();
        }
        catch(Exception e){
            
        }
    }

    public void printWelcome()
    {
         System.out.println("### Welcome: "+worker.getName()+" ###");
    }

    public void SellRentOrder()
    {
        System.out.println("Managing rent/sell orders?" +
                "\n(1) sell" +
                "\n(2) rent");

        int choice=0;
        
        do{

            choice=listener.getLineInt();

            if(choice==1){
                OrderSellUI orderSellUI=new OrderSellUI();
                orderSellUI.orderOrderSellProductManager();
            }

            if(choice==2){
                OrderRentUI orderRentUI=new OrderRentUI();
                orderRentUI.orderOrderRentProductManager();
            }
        }while(choice>2);
    }

    public void productManagingUI()
    {
        System.out.println("managing rent/sell product?" +
                "\n(1) sell" +
                "\n(2) rent");
        
        int choice=0;
        
        do{

            choice=listener.getLineInt();

            if(choice==1){
                SellUI sellProductUI=new SellUI();
                sellProductUI.sellProductManager();
            }
            if(choice==2){
                RentUI rentProductUI=new RentUI();
                rentProductUI.rentProductManager();
            }
        }while(choice>2);
    }


}
